<template>
  <div>
    <i-cell-group>
      <i-cell
        class="text"
        v-for="(item,idx) in list"
        :key="idx"
        :title="item.name"
        is-link
        :url="item.url"
      ></i-cell>
    </i-cell-group>
    <div class="logout-btn-wrap">
      <button @click="handleLogout">退出登录</button>
    </div>
  </div>
</template>

<script>
import {} from '@/utils'
// import { LOGOUT, NEW_LOGOUT } from '@/api'
import { LOGOUT } from '@/api'

export default {
  components: {},
  props: {},
  data () {
    return {
      list: [{ name: '密码设置', url: '/pages/mine/setting/password/main' }]
    }
  },
  computed: {},
  watch: {},
  created () {},
  mounted () {},
  onShow () {},
  methods: {
    handleLogout () {
      const vm = this
      vm
        .$dialog('确定要退出当前账号吗？')
        .then(r => {
          // vm.logout() // 老的
          vm.newLogout() // 新的
        })
        .catch(e => {
          // cancel
          // do nothing
        })
    },
    logout () {
      const vm = this

      LOGOUT(vm.$store.state.account.token)
        .then(r => {
          if (r.data.code === '0' && r.data.data) {
            // success
          } else {
            // fail
          }
          vm.logoutThen()
        })
        .catch(e => {
          vm.logoutThen()
          console.error(e)
        })
    },
    newLogout () {
      const vm = this
      vm.logoutThen()

      // NEW_LOGOUT()
      //   .then(r => {
      //     if (r.data.code === '0' && r.data.data) {
      //       // success
      //     } else {
      //       // fail
      //     }
      //     vm.logoutThen()
      //   })
      //   .catch(e => {
      //     vm.logoutThen()
      //     console.error(e)
      //   })
    },
    logoutThen () {
      let loginState = this.$cookie.get('loginState')
      let isOneClickDis = this.$cookie.get('isOneClickDis')
      let showData = this.$cookie.get('show-data')
      let showDataForm = this.$cookie.get('show-data-form')
      this.$cookie.clear()
      // let account = {
      //   providerId: '1000000000'
      // }
      // this.$store.commit('SET_ACCOUNT_INFO', account)
      this.$cookie.set('loginState', loginState)
      this.$cookie.set('isOneClickDis', isOneClickDis)
      this.$cookie.set('show-data', showData)
      this.$cookie.set('show-data-form', showDataForm)
      this.$router.new('/pages/login/login/main')
    }
  }
}
</script>

<style lang="scss" scoped>
.text {
  font-size: 20px;
}
.logout-btn-wrap {
  padding: 15px;
  position: absolute;
  width: 100%;
  bottom: 354px;
  left: 0;

  button {
    background-color: #626efd;
    color: #ffffff;
    font-size: 30rpx;
    width: 100%;
    text-align: center;
    border-radius: 25px;
    line-height: 40px;
  }
}
</style>
